﻿@model OMS.Models.FullOrderModelView

<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>

@{
    ViewBag.Title = "Edit Order";
}

<h2>This page is appointed for selecting and buying products</h2>

@if (Model.Order.Status == "created")
{
    @Html.ActionLink("Add item", "AddItem", new { OrderId = Model.Order.Id })
}

<div>
    <table align=center>
    <tr>
        <th>Item Number</th>
        <th>Name</th>
        <th>Description</th>
        <th>Dimension</th>
        <th>Price</th>
        <th>Quantity</th>
        <th></th>
    </tr>

@foreach (var order in Model.Order.OrderItems)
{
        <tr>
            <td>
                @Html.DisplayFor(i => order.ItemModel.Id)
            </td>
            <td>
                @Html.DisplayFor(i => order.ItemModel.Name)
            </td>
            <td>
                @Html.DisplayFor(i => order.ItemModel.Description)
            </td>
            <td>
                @Html.DisplayFor(i => order.Dimension)
            </td>
            <td>
                @Html.DisplayFor(i => order.Price)
            </td>
            <td>
                @Html.DisplayFor(i => order.Quantity)
            </td>
            <td>
            @if (Model.Order.Status == "created")
            {
                @Html.ActionLink("Edit", "EditItem", new { orderItemId = order.Id, orderId = Model.Order.Id })
                @Html.ActionLink("Delete", "DeleteItem", new { orderItemId = order.Id, orderId = Model.Order.Id })
            }
            </td>
        </tr>
}
</table>
</div>
<br />
@using (Html.BeginForm())
{
    @Html.ValidationSummary(true) {
        <div align=center>
            Totals <br />
            <table>
                <tr>
                    <td>Order Number</td>
                    <td>@Html.EditorFor(m => m.Order.OrderNumber)</td>
                    <td>@Html.ValidationMessageFor(m => m.Order.OrderNumber)</td>
                </tr>
                <tr>
                    <td>Status</td>
                    <td>@Html.DisplayFor(m => m.Order.Status)</td>
                </tr>
                <tr>
                    <td>Total Price</td>
                    <td>@Html.DisplayFor(m => m.Order.TotalPrice)</td>
                </tr>
                <tr>
                    <td>Total Number of Items</td>
                    <td>@Html.DisplayFor(m => m.Order.NumberOfItems)</td>
                </tr>
                <tr>
                    <td>Date of Ordering</td>
                    @Html.HiddenFor(m => m.Order.DateOfOrdering)
                    <td>@Html.DisplayFor(m => m.Order.DateOfOrdering)</td>
                </tr>
                <tr>
                    <td>Preferable Delivery Date</td>
                    <td>@Html.EditorFor(m => m.Order.PrefDate)</td>
                    <td>@Html.ValidationMessageFor(m => m.Order.PrefDate)</td>
                </tr>
                <tr>
                    <td>Delivery Date</td>
                    @Html.HiddenFor(m => m.Order.DeliveryDate)
                    <td>@Html.DisplayFor(m => m.Order.DeliveryDate)</td>
                </tr>
                <tr>
                    <td>Assignee</td>
                    <td>@Html.DropDownListFor(m => m.Order.Asignee,
                        new SelectList(ViewBag.Merches, "Value", "Text", ViewBag.SelectedMerch))</td>
                    <td>@Html.ValidationMessageFor(m => m.Order.Asignee)</td>
                </tr>
            </table>
        </div>
    <br />
        <div align=center>
            Card Info <br />
            <table>
                <tr>
                    <td>Credit Card Type</td>
                    <td>@Html.DropDownListFor(m => m.CreditCard._Type, new SelectList(
                       new string[] {"Visa","Master Card","American Express","Maestro"},Model.CreditCard._Type))</td>
                    <td>@Html.ValidationMessageFor(m => m.CreditCard._Type)</td>
                </tr>
                <tr>
                    <td>Credit Card Number</td>
                    <td>@Html.EditorFor(m => m.CreditCard.Number)</td>
                    <td>@Html.ValidationMessageFor(m => m.CreditCard.Number)</td>
                </tr>
                <tr>
                    <td>CVV2 Code (What is this?)</td>
                    <td>@Html.EditorFor(m => m.CreditCard.Cv2)</td>
                    <td>@Html.ValidationMessageFor(m => m.CreditCard.Cv2)</td>
                </tr>
                <tr>
                    <td>Expiry Date</td>
                    <td>@Html.EditorFor(m => m.CreditCard.ExpiryDate)</td>
                    <td>@Html.ValidationMessageFor(m => m.CreditCard.ExpiryDate)</td>
                </tr>
                <tr>
                    <td>Start Date (Maestro only)</td>
                    <td>@Html.EditorFor(m => m.CreditCard.StartDate)</td>
                    <td>@Html.ValidationMessageFor(m => m.CreditCard.StartDate)</td>
                </tr>
                <tr>
                    <td>Issue Number (Maestro only)</td>
                    <td>@Html.EditorFor(m => m.CreditCard.IssueNumber)</td>
                    <td>@Html.ValidationMessageFor(m => m.CreditCard.IssueNumber)</td>
                </tr>
            </table>
        </div>
    @Html.HiddenFor(m => m.Order.Id)
                                  }
   if (Model.Order.Status == "created")
   {
        <button type=submit name="submitButton" value="order">Order</button>
        <button type=submit name="submitButton" value="save">Save</button>
   }
        @Html.ActionLink("Cancel", "Ordering")
}